package com.linkoog.devtools.code_generator.template.render.engine.jtemplate;

import com.linkoog.devtools.code_generator.template.render.engine.TemplateEngine;
import com.linkoog.template.Engine;
import com.linkoog.template.Template;

import java.util.Map;

public class JtplTemplateEngine implements TemplateEngine {

    private final Engine engine;

    public JtplTemplateEngine(){
        Engine engine = Engine.use();
        engine.setDevMode(false);
        engine.setLeftTrimForIfForSwitch(true);
        this.engine =  engine;
    }

    @Override
    public String render(String templateContent, Map<String, Object> dataMap) throws Exception {
        if (templateContent == null || templateContent.trim().isEmpty()) {
            return "";
        }
        Template template = engine.getTemplateByString(templateContent);
        return template.renderToString(dataMap);
    }
}
